home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / sharewar / FFE / GRAPH.SWG / 0037_ST Picture Formats.pas < prev    next >
Pascal/Delphi Source File  |  1997-05-11  |  29KB  |  739 lines

  1.                            ST Picture Formats
  2.                            ------------------
  3.                                Edited by:
  4.  
  5.                               David Baggett
  6.                          5640 Vantage Point Road
  7.                          Columbia, MD  21044 USA
  8.                              (301)  596-4779
  9.                           (usenet: dmb@TIS.COM)
  10.  
  11.                    (Please report errors or additions)
  12.  
  13.            Copyright (C) 1988, 1989, 1990 by David M. Baggett
  14.  
  15.  
  16.     Non-profit redistribution of this document is permitted, provided
  17.     the document is not modified in any way.
  18.  
  19.     Reproduction of this document in whole or in part for  commercial
  20.     purposes is expressly forbidden without the prior written consent
  21.     of David M. Baggett.
  22.  
  23.     The  information  presented here is not guaranteed to be correct.
  24.     The editor and contributors will in no event be liable for direct,
  25.     indirect, incidental, or consequential damages resulting from the
  26.     use of the information in this document.
  27.  
  28.     This document is the product of many hours of volunteer work by a
  29.     large number of people. Please respect this -- do not violate the
  30.     distribution policy.
  31.  
  32.  
  33.                               CONTRIBUTORS
  34.   
  35.             Phil Blanchfield  Jason Blochowiak John Brochu**
  36.           David Brooks  Neil Forsyth  Stefan Hoehn Ken MacLeod   
  37.          Jim McCabe  Darek Mihocka    David Mumper  George Seto
  38.           Joe Smith  Greg Wageman  Roland Waldi* Gerry Wheeler
  39.  
  40.  
  41.                                 Contents 
  42.                                 --------
  43.  
  44.         NEOchrome                               *.NEO
  45.         NEOchrome Animation                     *.ANI
  46.         DEGAS                                   *.PI?   ? = 1, 2, 3
  47.         DEGAS Elite                             *.PI?   ? = 1, 2, 3
  48.         DEGAS Elite (Compressed)                *.PC?   ? = 1, 2, 3
  49.         Tiny                                    *.TN?   ? = 1, 2, 3, Y
  50.         Spectrum 512                            *.SPU
  51.         Spectrum 512 (Compressed)               *.SPC
  52.         Art Director                            *.ART
  53.         C.O.L.R. Object Editor Mural            *.MUR
  54.         Doodle                                  *.DOO
  55.         Animatic Film                           *.FLM
  56.         GEM Bit Image                           *.IMG
  57.         STAD                                    *.PAC
  58.         Imagic Film/Picture                     *.IC?   ? = 1, 2, 3
  59.         IFF                                     *.IFF
  60.         MacPaint                                *.MAC
  61.         PackBits Compression Algorithm
  62.  
  63.  
  64.                         Introductory Information
  65.                         ------------------------
  66. word    = 2 bytes
  67. long    = 4 bytes
  68. palette = Hardware color palette, stored as 16 words.  First word is
  69.           color register zero (background), last word is color register
  70.           15.  Each word has the form:
  71.  
  72.           Bit:  (MSB) 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
  73. (LSB)
  74.                       -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  75.                        0  0  0  0  0 R2 R1 R0  0 G2 G1 G0  0 B2 B1 B0
  76.  
  77.           R2 = MSB of red intensity
  78.           R0 = LSB of red intensity
  79.  
  80.           G2 = MSB of green intensity
  81.           G0 = LSB of green intensity
  82.  
  83.           B2 = MSB of blue intensity
  84.           B0 = LSB of blue intensity
  85.  
  86.           Intensity ranges from 0 (color not present) to 7 (highest
  87.           intensity).
  88.  
  89.           Example: { red = 7, green = 3, blue = 5 } -> 0735 (hex)
  90.  
  91.           Caveat:  It is wise to mask off the upper four bits of each
  92.                    palette entry, since a few programs store special
  93.                    information there (most notably Art Studio).
  94.  
  95.  
  96.                              The Formats
  97.                              -----------
  98.  
  99. <NEOchrome>     *.NEO
  100.  
  101. 1 word          flag byte [always 0]
  102. 1 word          resolution [0 = low res, 1 = medium res, 2 = high res]
  103. 16 words        palette
  104. 12 bytes        filename [usually "        .   "]
  105. 1 word          color animation limits.  High bit (bit 15) set if color
  106.                 animation data is valid.  Low byte contains color
  107. animation
  108.                 limits (4 most significant bits are left/lower limit,
  109.                 4 least significant bits are right/upper limit).
  110. 1 word          color animation speed and direction.  High bit (bit 15)
  111. set
  112.                 if animation is on.  Low order byte is # vblanks per
  113. step.
  114.                 If negative, scroll is left (decreasing).  Number of
  115. vblanks
  116.                 between cycles is |x| - 1
  117. 1 word          # of color steps (as defined in previous word) to
  118. display
  119.                 picture before going to the next.  (For use in slide
  120. shows)
  121. 1 word          image X offset [unused, always 0]
  122. 1 word          image Y offset [unused, always 0]
  123. 1 word          image width [unused, always 320]
  124. 1 word          image height [unused, always 200]
  125. 33 words        reserved for future expansion
  126. 16000 words     picture data (screen memory)
  127. -----------
  128. 32128 bytes     total
  129.  
  130.  
  131. <NEOchrome Animation>        *.ANI
  132.  
  133. NOTE:      To get this feature on versions 0.9 and later select the
  134. Grabber
  135.         icon and click both mouse buttons in the eye of the second R in
  136. the
  137.         word GRABBER.
  138.            Interestingly enough, some versions of NEO only require you
  139.         to press the right button, not both.  Hmmm...
  140.  
  141. 1 long          magic number BABEEBEA (hex) (seems to be ignored)
  142. 1 word          width of image in bytes (always divisible by 8)
  143. 1 word          height of image in scan lines
  144. 1 word          size of image in bytes + 10 (!)
  145. 1 word          x coordinate of image (must be divisible by 16) - 1
  146. 1 word          y coordinate of image - 1
  147. 1 word          number of frames
  148. 1 word          animation speed (# vblanks to delay between frames)
  149. 1 long          reserved; should be zero
  150. --------
  151. 22 bytes        total for header
  152.  
  153. ? words         image data (words of screen memory) for each frame, in 
  154.                 order
  155.  
  156.  
  157. <DEGAS>         *.PI1 (low resolution)
  158.                 *.PI2 (medium resolution)
  159.                 *.PI3 (high resolution)
  160.  
  161. 1 word          resolution (0 = low res, 1 = medium res, 2 = high res)
  162.                 Other bits may be used in the future; use a simple bit
  163.                 test rather than checking for specific word values.
  164. 16 words        palette
  165. 16000 words     picture data (screen memory)
  166. -----------
  167. 32034 bytes     total
  168.  
  169.  
  170. <DEGAS Elite>   *.PI1 (low resolution)
  171.                 *.PI2 (medium resolution)
  172.                 *.PI3 (high resolution)
  173.  
  174. 1 word          resolution (0 = low res, 1 = medium res, 2 = high res)
  175.                 Other bits may be used in the future; use a simple bit
  176.                 test rather than checking for specific word values.
  177. 16 words        palette
  178. 16000 words     picture data (screen memory)
  179. 4 words         left color animtion limit table (starting color numbers)
  180. 4 words         right color animation limit table (ending color numbers)
  181. 4 words         animation channel direction flag (0 = left, 1 = off, 2 =
  182. right)
  183. 4 words         128 - animation channel delay in 1/60's of a second. [0
  184. - 128]
  185.                 (I.e., subtract word from 128 to get 1/60th's of a
  186. second.)
  187. -----------
  188. 32066 bytes     total
  189.  
  190.  
  191. <DEGAS Elite (Compressed)>      *.PC1 (low resolution)
  192.                                 *.PC2 (medium resolution)
  193.                                 *.PC3 (high resolution)
  194.  
  195. 1 word          resolution (same as Degas, but high order bit is set;
  196.                 i.e., hex 8000 = low res, hex 8001 = medium res,
  197.                 hex 8002 = high res).  Other bits may be used in the
  198.                 future; use a simple bit test rather than checking
  199.                 for specific word values.
  200. 16 words        palette
  201. < 32000 bytes   control/data bytes
  202. 4 words         left color animation limit table (starting color
  203. numbers)
  204. 4 words         right color animation limit table (ending color numbers)
  205. 4 words         animation channel direction flag [0 = left, 1 = off, 2 =
  206. right]
  207. 4 words         128 - animation channel delay in 1/60's of a second. [0
  208. - 128]
  209.                 (I.e., subtract word from 128 to get 1/60th's of a
  210. second.)
  211. -----------
  212. < 32066 bytes   total
  213.  
  214. Compression Scheme:
  215.  
  216.    PackBits compression is used (see below).  Each scan line is
  217. compressed
  218. separately; i.e., all data for a given scan line appears before any data
  219. for the next scan line.  The scan lines are specified from top to bottom
  220. (i.e., 0 is first).  For each scan line, all the data for a given bit
  221. plane
  222. appears before any data for the next higher order bit plane.  Note this
  223. is
  224. identical to the IFF 'BODY' image data.
  225.    To clarify:  The first data in the file will be the data for the
  226. lowest
  227. order bit plane of scan line zero, followed by the data for the next
  228. higher
  229. order bit plane of scan line zero, etc., until all bit planes have been
  230. specified for scan line zero.  The next data in the file will be the
  231. data
  232. for the lowest order bit plane of scan line one, followed by the data
  233. for
  234. the next higher order bit plane of scan line one, etc., until all bit
  235. planes
  236. have been specified for all scan lines.
  237.  
  238. Caveats:
  239.  
  240.    DEGAS Elite's picture loading routine places some restrictions on
  241. compressed DEGAS files:
  242.  
  243.         o Elite uses a 40-byte buffer to store data being decompressed.
  244.  
  245.         o Whenever a control command is encountered, bytes are stuffed
  246.         in this buffer.
  247.  
  248.         o The buffer is only emptied when there are EXACTLY 40
  249.         characters in it.
  250.  
  251. The important conclusion here is that
  252.  
  253.         No control command may cause the buffer to have more than 40
  254.         bytes in it.  In other words, all control commands must end on
  255.         or before the 40-byte boundary.
  256.  
  257. Any picture violating the last condition will cause Elite to get a bus
  258. error when the picture is loaded.
  259.  
  260.  
  261. <Tiny>  *.TNY (any resolution)
  262.         *.TN1 (low resolution)
  263.         *.TN2 (medium resolution)
  264.         *.TN3 (high resolution)
  265.  
  266.    Several people have reported sightings of mutated Tiny pictures that
  267. do not follow the standard format, so let's be careful out there.  What
  268. is described here is the format that David Mumper's original
  269. TNYSTUFF.PRG produces.
  270.  
  271. 1 byte          resolution (same as NEO, but +3 indicates rotation
  272.                 information also follows)
  273.  
  274. If resolution > 2 {
  275. 1 byte          left and right color animation limits.  High 4 bits
  276.                 hold left (start) limit; low 4 bits hold right (end)
  277.                 limit
  278. 1 byte          direction and speed of color animation (negative value
  279.                 indicates left, positive indicates right, absolute value
  280.                 is delay in 1/60's of a second.
  281. 1 word          color rotation duration (number of iterations)
  282. }
  283.  
  284. 16 words        palette
  285. 1 word          number of control bytes
  286. 1 word          number of data words
  287. 3-10667 bytes   control bytes
  288. 1-16000 words   data words
  289. -------------
  290. 42-32044 bytes  total
  291.  
  292. Control byte meanings:
  293.  
  294.         For a given control byte, x:
  295.  
  296.         x < 0   Absolute value specifies the number of unique words to
  297.                 take from the data section (from 1 to 127)
  298.         x = 0   1 word is taken from the control section which specifies
  299.                 the number of times to repeat the next data word (from
  300.                 128 to 32767)
  301.         x = 1   1 word is taken from the control section which specifies
  302.                 the number of unique words to be taken from the data
  303.                 section (from 128 - 32767)
  304.         x > 1   Specifies the number of times to repeat the next word
  305.                 taken from the data section (from 2 to 127)
  306.  
  307. Format of expanded data:
  308.  
  309.    The expanded data is not simply screen memory bitmap data; instead,
  310. the 
  311. data is divided into four sets of vertical columns.  (This results in
  312. better compression.)  A column consists of one specific word taken
  313. from each scan line, going from top to bottom.  For example, column 1 
  314. consists of word 1 on scanline 1 followed by word 1 on scanline 2, etc., 
  315. followed by word 1 on scanline 200.
  316.    The columns appear in the following order:
  317.  
  318.    1st set contains columns 1, 5,  9, 13, ..., 69, 73, 77 in order
  319.    2nd set contains columns 2, 6, 10, 14, ..., 70, 74, 78 in order
  320.    3rd set contains columns 3, 7, 11, 15, ..., 71, 75, 79 in order
  321.    4th set contains columns 4, 8, 12, 16, ..., 72, 76, 80 in order
  322.  
  323. Note that Tiny partitions the screen this way regardless of resolution;
  324. i.e., 
  325. these aren't bitplanes.  For example, medium resoltion only has two
  326. bitplanes, 
  327. but Tiny still divides medium resolution pictures into four parts.
  328.  
  329.  
  330. <Spectrum 512>  *.SPU
  331.  
  332. 80 words        first scan line of picture (unused) -- should be zeroes
  333. 15920 words     picture data (screen memory) for scan lines 1 through
  334. 199
  335. 9552 words      3 palettes for each scan line (the top scan line is
  336.                 not included because Spectrum 512 can't display it)
  337. -----------
  338. 51104 bytes     total
  339.  
  340.  
  341. <Spectrum 512 (Compressed)>        *.SPC
  342.  
  343. 1 word          flag word [$5350 or "SP"]
  344. 1 word          reserved for future use [always 0]
  345. 1 long          length of data bit map
  346. 1 long          length of color bit map
  347. <= 32092 bytes  compressed data bit map
  348. <= 17910 bytes  compressed color bit map
  349. --------------
  350. <= 50014 bytes   total
  351.  
  352. Data compression:
  353.  
  354.    Compression is via a modified run length encoding (RLE) scheme,
  355. similar to DEGAS compressed and Tiny.  The data map is stored as a
  356. sequence of records.  Each record consists of a header byte followed by
  357. one or more data bytes.  The meaning of the header byte is as follows:
  358.  
  359.         For a given header byte, x:
  360.  
  361.            0 <= x <= 127   Use the next x + 1 bytes literally (no
  362. repetition)
  363.         -128 <= x <=  -1   Use the next byte -x + 2 times
  364.  
  365. The data appears in the following order:
  366.  
  367.         1. Picture data, bit plane 0, scan lines 1 - 199
  368.         2. Picture data, bit plane 1, scan lines 1 - 199
  369.         3. Picture data, bit plane 2, scan lines 1 - 199
  370.         4. Picture data, bit plane 3, scan lines 1 - 199
  371.  
  372. Decompression of data ends when 31840 data bytes have been used.
  373.  
  374. Color map compression:
  375.  
  376.    Each 16-word palette is compressed separately.  There are three
  377. palettes for each scan line (597 total).  The color map is stored as a
  378. sequence of records.  Each record starts with a 1-word bit vector which
  379. specifies which of the 16 palette entries are included in the data
  380. following the bit vector (1 = included, 0 = not included).  If a palette
  381. entry is not included, it is assumed to be zero (black).  The least
  382. significant bit of the bit vector refers to palette entry zero, while
  383. the
  384. most significant bit refers to palette entry 15.  Bit 15 must be zero,
  385. since Spectrum 512 does not use palette entry 15.  Bit 0 should also be
  386. zero, since Spectrum 512 always makes the background color black.
  387.    The words specifying the values for the palette entries indicated in
  388. the bit vector follow the bit vector itself, in order (0 - 15).
  389.  
  390.  
  391. <Art Director>  *.ART (low resolution only)
  392.  
  393. 16000 words     picture data (screen memory)
  394. 16 words        palette
  395. 15 * 16 words   15 more palettes for animation
  396. -------------
  397. 32512 bytes     total
  398.  
  399.  
  400. <C.O.L.R. Object Editor Mural>        *.MUR (low resolution only)
  401.  
  402. 16000 words     picture data (screen memory)
  403.                 (palettes are stored in separate files)
  404. -----------
  405. 32000 bytes     total
  406.  
  407.  
  408. <Doodle>        *.DOO (high resolution only)
  409.  
  410. 16000 words     picture data (screen memory)
  411. -----------
  412. 32000 bytes     total
  413.  
  414.  
  415. <Animatic Film> *.FLM (low resolution only)
  416.  
  417. 1 word          number of frames
  418. 16 words        palette
  419. 1 word          speed (0 - 99; value is 99 - # vblanks to delay between
  420. frames)
  421. 1 word          direction (0 = forwards, 1 = backwards)
  422. 1 word          end action (what to do after the last frame)
  423.                 0 = pause, then repeat from beginning
  424.                 1 = immediately repeat from beginning
  425.                 2 = reverse (change direction)
  426. 1 word          width of film in pixels
  427. 1 word          height of film in pixels
  428. 1 word          Animatic version number (major)
  429. 1 word          Animatic version number (minor)
  430. 1 long          magic number 27182818 (hex)
  431. 3 longs         reserved for expansion (should be all zeros)
  432. --------
  433. 32 words        total for header
  434.  
  435. ? words         image data (words of screen memory) for each frame, in
  436. order
  437.  
  438.  
  439. <GEM Bit Image> *.IMG
  440.  
  441. 1 word          version number of image file [1]
  442. 1 word          length of header in words [usually 8]
  443. 1 word          number of color planes [1 for monochrome]
  444. 1 word          pattern length in bytes [1-8, usually 2 for screen
  445. images]
  446. 1 word          pixel width in microns (1/1000 mm, 25400 microns per
  447. inch)
  448. 1 word          pixel height in microns
  449. 1 word          line width in pixels
  450. 1 word          number of lines
  451. -------
  452. ? words         header length defined in 2nd word of header
  453.  
  454. ? bytes         data
  455.  
  456. NOTES:  If the image is a color image (planes > 1), the planes are
  457. stored
  458. separately starting with plane 0.  There is, however, no standard way of
  459. storing the color palette.  Some programs may save the palette in
  460. separate
  461. files, some may extend the header.  For this reason, you should never
  462. assume the header is 8 words long, always get the header length from the
  463. 2nd word of the header.  Also, the line width in the 7th word is the
  464. number
  465. of pixels in a line.  Since the data is encoded in byte-wide packets,
  466. the
  467. actual unpacked line width is always a multiple of 8, and may be 1-7
  468. pixels
  469. longer than the length specified in the header.
  470.  
  471. For each byte x in the data section,
  472.  
  473.         x = 0           Pattern/scanline run.
  474.                         Read the next byte, n (unsigned).
  475.  
  476.                         If n > 0 then:
  477.                                 Read a number of bytes equal to the
  478. "pattern
  479.                                 length" word in the header.  Repeat this
  480.                                 pattern n times.
  481.  
  482.                         If n = 0 then:
  483.                                 Scanline run.  Data for the next
  484. scanline
  485.                                 is to be used multiple times.  Read the
  486.                                 following record:
  487.  
  488.                                 1 byte          flag byte [$FF]
  489.                                 1 byte          number of times to use
  490.                                                 next scanline data
  491.  
  492.                                 The data for the next scanline follows,
  493.                                 compressed normally.
  494.  
  495.         x = 80 (hex)    Uncompressed bit string.  The next byte
  496.                         determines the number of bytes to use
  497.                         literally.  The literal data bytes follow.
  498.  
  499.         otherwise       Solid run.  The value of x determines
  500.                         what to draw.  The high bit specifies whether
  501.                         the pixels are set or cleared.  A 1 indicates
  502.                         a byte-run using $FF, a 0 indicates a byte-run
  503.                         using $00.  The low 7 bits, taken as an unsigned
  504.                         quantity, specify the length of the run in
  505. bytes.
  506.  
  507.  
  508. <STAD>          *.PAC (high resolution only)
  509.  
  510. 4 bytes         "pM86" (vertically packed) or "pM85" (horizontally
  511. packed)
  512. 1 byte          id byte
  513. 1 byte          pack byte (most frequently occuring byte in bitmap)
  514. 1 byte          "special" byte
  515. -------
  516. 7 bytes         total for header
  517.  
  518. ? bytes         data
  519.  
  520. The data is encoded as follows.  For each byte x in the data section:
  521.  
  522.         x = id byte             Read one more byte, n.  Use pack byte 
  523.                                 n + 1 times.
  524.         x = "special" byte      Read two more bytes, d, and n (in
  525. order).
  526.                                 Use byte d n times.
  527.         otherwise               Use byte x literally.
  528.  
  529.  
  530. <Imagic Film/Picture>           *.IC1 (low resolution)
  531.                                 *.IC2 (medium resolution)
  532.                                 *.IC3 (high resolution)
  533.  
  534. 4 bytes         "IMDC"
  535. 1 word          resolution (0 = low res, 1 = medium res, 2 = high res)
  536. 16 words        palette
  537. 1 word          date (GEMDOS format)
  538. 1 word          time (GEMDOS format)
  539. 8 bytes         name of base picture file (for delta compression), or
  540. zeroes
  541. 1 word          length of data (?)
  542. 1 long          registration number
  543. 8 bytes         reserved
  544. 1 byte          compressed? (0 = no, 1 = yes)
  545.  
  546. If compressed {
  547. 1 byte          delta-compressed? (-1 = no, > -1 = yes)
  548. 1 byte          ?
  549. 1 byte          escape byte
  550. }
  551. -------
  552. 65 bytes        total for header (68 bytes if compressed)
  553.  
  554. ? bytes         data
  555.  
  556.    Compressed data may be either stand-alone or delta-compressed
  557. (relative
  558. to the base picture named in the header).  Delta compression involves
  559. storing only how the picture differs from the base picture (i.e., only
  560. portions of the screen that have changed are stored).  This is used to
  561. to encode animated sequences efficiently.
  562.  
  563. Compressed data, stand-alone:
  564.  
  565. For each byte x in the data section:
  566.  
  567.         x = escape byte         Read one more byte, n.  (n is unsigned).
  568.  
  569.                                 If n >= 2, use the next byte n times.
  570.                                 If n = 1, keep reading bytes until a
  571.                                 byte k not equal to 1 is encountered.
  572.                                 Then read the next byte d.
  573.                                 If the number of 1 bytes encountered is
  574. o,
  575.                                 use d (256 * o + k) times.  I.e.,
  576.  
  577.                                 if (n == 1) {
  578.                                         o = 0;
  579.                                         while (n == 1) {
  580.                                                 o++;
  581.                                                 n = next byte;
  582.                                         }
  583.  
  584.                                         k = n;
  585.                                         d = next byte;
  586.  
  587.                                         Use d (256 * o + k) times.
  588.                                 }
  589.                                 else {
  590.                                         d = next byte;
  591.                                         Use d (n) times.
  592.                                 }
  593.  
  594.         x != escape byte        Use x literally.
  595.  
  596. Compressed data, delta compressed:
  597.  
  598. For each byte x in the data section:
  599.  
  600.         x = escape byte         Read one more byte, n.  (n is unsigned).
  601.  
  602.                                 If n >= 3, use the next byte n times.
  603.                                 If n = 1, do the same as for n = 1 in
  604.                                 stand-alone compression (above).
  605.                                 If n = 2, then set n = next byte.
  606.                                         If n = 0, end of picture.
  607.                                         If n >= 2, take n bytes from
  608. base
  609.                                         picture.
  610.                                         If n = 1, do the same as for n =
  611. 1
  612.                                         in stand-alone compression
  613. (above),
  614.                                         but take (256 * o + k) bytes
  615. from 
  616.                                         base picture.
  617.  
  618.         x != escape byte        Use x literally.
  619.  
  620.  
  621. <IFF Format>    *.IFF
  622.  
  623. 4 bytes         "FORM" (FORM chunk ID)
  624. 1 long          length of file that follows
  625. 4 bytes         "ILBM" (InterLeaved BitMap file ID)
  626.  
  627. 4 bytes         "BMHD" (BitMap HeaDer chunk ID)
  628. 1 long          length of chunk [20]
  629. 20 bytes        1 word = image width in pixels
  630.                 1 word = image height in lines
  631.                 1 word = image x-offset [usually 0]
  632.                 1 word = image y-offset [usually 0]
  633.                 1 byte = # bitplanes
  634.                 1 byte = mask (0=no, 1=impl., 2=transparent, 3=lasso)
  635.                 1 byte = compressed [1] or uncompressed [0]
  636.                 1 byte = unused [0]
  637.                 1 word = transparent color (for mask=2)
  638.                 1 byte = x-aspect [5=640x200, 10=320x200/640x400,
  639. 20=320x400]
  640.                 1 byte = y-aspect [11]
  641.                 1 word = page width (usually the same as image width)
  642.                 1 word = page height (usually the same as image height)
  643.  
  644. 4 bytes         "CMAP" (ColorMAP chunk ID)
  645. 1 long          length of chunk [3*n where n is the # colors]
  646. 3n bytes        3 bytes per RGB color.  Each color value is a byte
  647.                 and the actual color value is left-justified in the
  648.                 byte such that the most significant bit of the value
  649.                 is the MSB of the byte.  (ie. a color value of 15 ($0F)
  650.                 is stored as $F0)  The bytes are stored in R,G,B order.
  651.  
  652. 4 bytes         "CRNG" (Color RaNGe chunk ID)
  653. 1 long          length of chunk [8]
  654. 8 bytes         1 word = reserved [0]
  655.                 1 word = animation speed (16384 = 60 steps per second)
  656.                 1 word = active [1] or inactive [0]
  657.                 1 byte = left/lower color animation limit
  658.                 1 byte = right/upper color animation limit
  659.  
  660. 4 bytes         "CAMG" (Commodore AMiGa viewport mode chunk ID)
  661. 1 long          length of chunk [4]
  662. 1 long          viewport mode bits (bit 11 = HAM, bit 3 = interlaced)
  663.  
  664. 4 bytes         "BODY" (BODY chunk ID)
  665. 1 long          length of chunk [# bytes of image data that follow]
  666. ? bytes         actual image data
  667.  
  668. NOTES: Some of these chunks may not be present in every IFF file, and
  669. may
  670. not be in this order.  You should always look for the ID bytes to find a
  671. certain chunk.  All chunk IDs are followed by a long value that tells
  672. the
  673. size of the chunk.  This is the number of bytes that FOLLOW the 4 ID
  674. bytes
  675. and size longword.  The exception to this is the FORM chunk.  The size
  676. longword that follows the FORM ID is the size of the remainder of the
  677. file.
  678. The FORM chunk must always be the first chunk in an IFF file.
  679.  
  680. The R,G,B ranges of AMIGA and ST are different (AMIGA 0...15, ST 0...7),
  681. as is the maximum number of bitplanes (AMIGA: 5, ST: 4).
  682.  
  683. Format of body data
  684.  
  685. An expanded picture is simply a bitmap.  The packing method is PackBits
  686. (see below), and is identical to MacPaint and DEGAS Elite compressed.
  687.  
  688. The (decompressed) body data appears in the following order:
  689.  
  690.         line 1 plane 0 ... line 1 plane 1 ... ... line 1 plane m
  691.         [line 1 mask (if appropriate)]
  692.         line 2 plane 0 ... line 2 plane 1 ... ... line 2 plane m
  693.         [line 2 mask (if appropriate)]
  694.         ...
  695.         line x plane 0 ... line x plane 1 ... ... line x plane m
  696.         [line x mask (if appropriate)]
  697.  
  698. The FORM chunk identifies the type of data:
  699.  
  700.         "ILBM" = interleaved bit map
  701.         "8SVX" = 8-bit sample voice
  702.         "SMUS" = simple music score
  703.         "FTXT" = formatted text (Amiga)
  704.  
  705.  
  706. <MacPaint>      *.MAC
  707.  
  708. 1 long          version number [0=ignore header, 2=header valid]
  709. 38 * 8 bytes    8x8 brush/fill patterns.  Each byte is a pattern row,
  710.                 and the bytes map the pattern rows top to bottom.  The
  711.                 patterns are stored in the order they appear at the
  712. bottom
  713.                 of the MacPaint screen top to bottom, left to right.
  714. 204 bytes       unused
  715. -------------
  716. 512 bytes       total for header
  717. < 51200 bytes   compressed bitmap data
  718. -------------
  719. < 51712 bytes   total
  720.  
  721. NOTE:  The version number is actually a flag to MacPaint to indicate if
  722. the brush/fill patterns are present in the file.  If the version is 0,
  723. the default patterns are used.  Therefore you can simply save a MacPaint
  724. file by writing a blank header (512 $00 bytes), followed by the packed
  725. image data.
  726.  
  727. Bitmap compression:
  728.  
  729.    The bitmap data is for a 576 pixel by 720 pixel monochrome image.
  730. The packing method is PackBits (see below).  There are 72 bytes per
  731. scan line.  Each bit represents one pixel; 0 = white, 1 = black.
  732.  
  733.  
  734. <PackBits Compression Algorithm>
  735.  
  736. The following packing algorithm originated on the Mac, was adopted by
  737. Electronic Arts/Commodore for use in the IFF standard, and then by Tom
  738. Hudson for use in DEGAS Elite.  The algorithm is currently used in
  739. MacPaint, IFF, and DEGAS Elite com